package test;

import java.util.Scanner;

public class TenXun3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for (int i = 0; i < num; i++) {
            System.out.println(getRes(scanner.nextInt()));
        }
    }

    private static int getRes(int nextInt) {
        int lastNum = nextInt / 2;
        int max = 0;
        for (int i = 1; i <= lastNum; i++) {
            max = Math.max(max,getSum(i,nextInt - i));
        }
        return max;
    }

    private static int getSum(int num1, int num2) {
        int sum = 0;
        String numStr1 = String.valueOf(num1);
        String numStr2 = String.valueOf(num2);
        for (int i = 0; i < numStr1.length(); i++) {
            sum += numStr1.charAt(i) - '0';
        }
        for (int i = 0; i < numStr2.length(); i++) {
            sum += numStr2.charAt(i) - '0';
        }
        return sum;
    }
}
